package com.android.slide;

import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.android.slide.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding mainBinding;
    private ViewPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(mainBinding.getRoot());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), getHomeFragment(), getHomeTitle());
        mainBinding.viewPagerHome.setAdapter(pagerAdapter);
        mainBinding.tabLayoutHome.setViewPager(mainBinding.viewPagerHome);
        mainBinding.tabLayoutHome.setCurrentTab(0);
        mainBinding.viewPagerHome.setOffscreenPageLimit(getHomeTitle().size());

    }

    public static List<String> getHomeTitle() {
        List<String> mTitles = new ArrayList<>();
        mTitles.add("Android");
        mTitles.add("Java");
        mTitles.add("HTML");
        mTitles.add("Python");
        mTitles.add("C++");
        return mTitles;
    }

    public static List<Fragment> getHomeFragment() {
        List<Fragment> mFragments = new ArrayList<>();
        mFragments.add(MainFragment.createFragment(0));
        mFragments.add(MainFragment.createFragment(1));
        mFragments.add(MainFragment.createFragment(2));
        mFragments.add(MainFragment.createFragment(3));
        mFragments.add(MainFragment.createFragment(4));
        return mFragments;
    }
}